local jueya = fk.CreateSkill {
  name = "mini__jueyaq",
  tags = { Skill.Limited },
}

Fk:loadTranslationTable {
  ["mini__jueyaq"] = "绝涯",
  [":mini__jueyaq"] = "限定技，当你进入濒死状态时，你可以将所有手牌以任意顺序置于牌堆顶，然后将体力回复至1点。" ..
      "若如此做，当前回合结束后，你执行一个额外回合。",

  ["$mini__jueyaq1"] = "身扶幼主出重围，血染征袍透甲红！",
  ["$mini__jueyaq2"] = "枪挑万军辟生路，当阳谁敢与争锋！",
}

jueya:addEffect(fk.EnterDying, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return
        target == player and
        player:hasSkill(jueya.name) and
        not player:isKongcheng() and
        player:usedSkillTimes(jueya.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = player:getCardIds("h")
    cards = room:askToGuanxing(
      player,
      {
        cards = cards,
        bottom_limit = { 0, 0 },
        skill_name = jueya.name,
        skip = true,
      }
    ).top
    room:moveCards {
      ids = table.reverse(cards),
      from = player,
      toArea = Card.DrawPile,
      moveReason = fk.ReasonPut,
      skillName = jueya.name,
      proposer = player,
    }
    if player:isAlive() and player.hp < 1 then
      room:recover {
        num = 1 - player.hp,
        who = player,
        skillName = jueya.name,
      }
      if player:isAlive() then
        player:gainAnExtraTurn()
      end
    end
  end
})

return jueya
